<template>
  <div class="login-container flx-center">
    <div class="login-box">
      <SwitchDark class="dark" />
      <div class="login-left">
        <img class="login-left-img" src="@/assets/images/login_left.png" alt="login" />
      </div>
      <div class="login-form">
        <div class="login-logo">
          <img class="login-icon" src="@/assets/images/CYBERWING-LOGO.png" alt="" />
          <h2 class="logo-text">{{ SYSTEM_CONFIG.APP_NAME }}</h2>
        </div>
        <login-form ref="loginFormRef" :random-code="randomCodeValidate"></login-form>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts" name="login">
import { onBeforeMount, Ref, ref } from "vue";
import LoginForm from "./components/LoginForm.vue";
import SwitchDark from "@/components/SwitchDark/index.vue";
import { getSysConfig } from "@/api/modules/system";
import { AxiosResponse } from "axios";
import { SYSTEM_CONFIG } from "@/config/system";
import { JxtechSysConfig } from "@/stores/interface/sysconfig";
import { useSysconfigrStore } from "@/stores/modules/sysconfig";

const sysConfigState = useSysconfigrStore();
const loginFormRef = ref<InstanceType<typeof LoginForm>>();
let randomCodeValidate: Ref<Boolean> = ref(false);

onBeforeMount(() => {
  if (!sysConfigState.appId) {
    // 获取系统配置信息
    getSysConfig()
      .then((Response: AxiosResponse<JxtechSysConfig>) => {
        randomCodeValidate.value = Response.data.randomCode;
        // verify校验规则
        loginFormRef.value.verifyRuleswitch(Response.data.randomCode);
        // 存储vuex
        sysConfigState.setSysConfig(Response.data);
      })
      .catch((Accident: AxiosResponse<any>) => {
        console.log(Accident);
      });
  }
});
</script>

<style scoped lang="scss">
@import "./index.scss";
</style>
